<?php namespace App\Controllers;

/**
 * @author Andy Brookes 
 * @author Andy Brookes <andybrookestar  at gmail dot   com>
 */


use CodeIgniter\Controller;
use \App\Models\BlogModel;
use TCPDF;



class ProducePDF  extends BaseController
{




protected $myDate;
protected $myTime;




				 public function __construct() 
				    {
								parent::__construct();
						       $this->myTime = parent::getTime();
						        $this->myDate= date("d/m/Y",$this->myTime); 	
					
			       }


   public function getPdf($slug)
   
   {
	 	    
	    $handle= new BlogModel();
	   $result= $handle->getArticle($slug);
	  $mytitle= $result["slug"];
	 $mystring= $result["article"];
	$mystring = $mytitle."<br><br>".$mystring;
	 $theImage = $result["image"];
	 $myStringStripTags= strip_tags($mystring, ['p', 'a', 'h4', 'h1','h3','h2']);
	 echo "start of using TCPDF";
	 $html2pdf = new  TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
	
	
	
	$html2pdf->setTitle("hello world");
	$html2pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
	$html2pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
	$html2pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
	$html2pdf->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM);
	$html2pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
	$html2pdf->setFontSubsetting(true);
	$html2pdf->SetFont('dejavusans', '', 12, '', true);
	$html2pdf-> AddPage('P',"A4");
	$html2pdf->Image(base_url().'/blogImages/'.$theImage, '', 45, 50, 50, 'JPG', false);
	$html2pdf->writeHTMLCell($w=0, $h=0, $x='', $y='100', $mystring, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
	ob_end_clean();
	$html2pdf->Output($mytitle.".pdf", 'D');

	 }  
      
    
	
									



}
  
